import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'
import Index from '../views/index.vue'
import Login from '../views/login.vue'
import Logon from '../views/logon.vue'
import Sreen from '../views/screen.vue'
import {
	Message
} from "element-ui"

Vue.use(VueRouter)
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
	return VueRouterPush.call(this, to).catch((err) => err)
}

const routes = [{
	path: '/',
	name: 'view-index',
	component: Index,
	children: [
		{
			path: '/',
			name: 'view-sreen',
			component: () => import( /* webpackChunkName: 'view-dashboard' */
				'../views/sreen/index.vue')
		},
		{
			path: '/station',
			name: 'view-station',
			component: () => import( /* webpackChunkName: 'view-dashboard' */
				'../views/station/index.vue')
		},
		{
			path: '/rectify',
			name: 'view-rectify',
			component: () => import( /* webpackChunkName: 'view-dashboard' */
				'../views/rectify/index.vue')
		},
		{
			path: '/effective',
			name: 'view-effective',
			component: () => import( /* webpackChunkName: 'view-dashboard' */
				'../views/effective/index.vue')
		},
		{
			path: '/distribute',
			name: 'view-distribute',
			component: () => import( /* webpackChunkName: 'view-dashboard' */
				'../views/distribute/index.vue')
		},
		{
			path: '/screen',
			name: 'view-dashboard',
			component: () => import( /* webpackChunkName: 'view-dashboard' */
				'../views/dashboard/index.vue')
		},
		{
			path: '/menu',
			name: 'view-menu',
			component: () => import( /* webpackChunkName: 'view-menu' */ '../views/menu/index.vue')
		},
		{
			path: '/admin',
			name: 'view-admin',
			component: () => import( /* webpackChunkName: 'view-admin' */ '../views/admin/index.vue')
		},
		{
			path: '/role',
			name: 'view-role',
			component: () => import( /* webpackChunkName: 'view-role' */ '../views/role/index.vue')
		},
		{
			path: '/admin-log',
			name: 'view-admin-log',
			component: () => import( /* webpackChunkName: 'view-admin-log' */
				'../views/admin-log/index.vue')
		},
		{
			path: '/system-config',
			name: 'view-system-config',
			component: () => import( /* webpackChunkName: 'view-system-config' */
				'../views/system-config/index.vue')
		},
		{
			path: '/bi',
			name: 'view-bi',
			component: () => import( /* webpackChunkName: 'view-bi' */ '../views/bi/index.vue')
		},

		// 高速
		// 题目
		{
			path: '/gsTimu',
			name: 'gsTimu',
			component: () => import( /* webpackChunkName: 'view-gsTimu' */
				'../views/gsTimu/index.vue')
		},
		{
			path: '/gsPrize',
			name: 'gsPrize',
			component: () => import( /* webpackChunkName: 'view-gsPrize' */
				'../views/gsPrize/index.vue')
		},
		{
			path: '/gsWinningRecord',
			name: 'gsWinningRecord',
			component: () => import( /* webpackChunkName: 'view-gsWinningRecord' */
				'../views/gsWinningRecord/index.vue')
		},
		{
			path: '/gsEmployeeList',
			name: 'gsEmployeeList',
			component: () => import( /* webpackChunkName: 'view-gsEmployeeList' */
				'../views/gsEmployeeList/index.vue')
		},
		{
			path: '/gsRoadSection',
			name: 'gsRoadSection',
			component: () => import( /* webpackChunkName: 'view-gsRoadSection' */
				'../views/gsRoadSection/index.vue')
		},
		// 部门列表
		{
			path: '/department',
			name: 'department',
			component: () => import( /* webpackChunkName: 'view-department' */
				'../views/department/index.vue')
		},
		// 题目分类列表
		{
			path: '/topicClassification',
			name: 'topicClassification',
			component: () => import( /* webpackChunkName: 'view-topicClassification' */
				'../views/topicClassification/index.vue')
		},
		// 用户列表
		{
			path: '/userList',
			name: 'userList',
			component: () => import( /* webpackChunkName: 'view-userList' */
				'../views/userList/index.vue')
		},
		//用户答题详情列表
		{
			path: '/userAnswer',
			name: 'userAnswer',
			component: () => import( /* webpackChunkName: 'view-userAnswer' */
				'../views/userAnswer/index.vue')
		},
		//认同审核列表
		{
			path: '/identifiedWorkOrder',
			name: 'identifiedWorkOrder',
			component: () => import( /* webpackChunkName: 'view-identifiedWorkOrder' */
				'../views/identifiedWorkOrder/index.vue')
		},
		//一般审核列表
		{
			path: '/generaWorkOrder',
			name: 'generaWorkOrder',
			component: () => import( /* webpackChunkName: 'view-generaWorkOrder' */
				'../views/generaWorkOrder/index.vue')
		},
		{
			path: '/noIdentifiedWorkOrder',
			name: 'noIdentifiedWorkOrder',
			component: () => import( /* webpackChunkName: 'view-noIdentifiedWorkOrder' */
				'../views/noIdentifiedWorkOrder/index.vue')
		},
		//待办列表
		{
			path: '/backlogList',
			name: 'backlogList',
			component: () => import( /* webpackChunkName: 'view-backlogList' */
				'../views/backlogList/index.vue')
		},
		//消息列表
		{
			path: '/messageList',
			name: 'messageList',
			component: () => import( /* webpackChunkName: 'view-messageList' */
				'../views/messageList/index.vue')
		},
		//题目选项答题次数统计表
		{
			path: '/topicOptionStatistics',
			name: 'topicOptionStatistics',
			component: () => import( /* webpackChunkName: 'view-topicOptionStatistics' */
				'../views/topicOptionStatistics/index.vue')
		},
		//设置
		{
			path: '/setting',
			name: 'setting',
			component: () => import( /* webpackChunkName: 'view-setting' */
				'../views/setting/index.vue')
		},
		//收费站列表
		{
			path: '/tollStation',
			name: 'tollStation',
			component: () => import( /* webpackChunkName: 'view-tollStation' */
				'../views/tollStation/index.vue')
		},
		//问卷调查列表数据分析
		{
			path: '/questionnaireSurveyListDataAnalysis',
			name: 'questionnaireSurveyListDataAnalysis',
			component: () => import( /* webpackChunkName: 'view-questionnaireSurveyListDataAnalysis' */
				'../views/questionnaireSurveyListDataAnalysis/index.vue')
		},
		//路段工单统计
		{
			path: '/roadWorkOrderStatistics',
			name: 'roadWorkOrderStatistics',
			component: () => import( /* webpackChunkName: 'view-roadWorkOrderStatistics' */
				'../views/roadWorkOrderStatistics/index.vue')
		},
		//其他选项描述
		{
			path: '/otherStatistics',
			name: 'otherStatistics',
			component: () => import( /* webpackChunkName: 'view-otherStatistics' */
				'../views/otherStatistics/index.vue')
		},
		//问卷大屏
		{
			path: '/questionnaire',
			name: 'questionnaire',
			component: () => import( /* webpackChunkName: 'view-questionnaire' */
				'../views/questionnaire/index.vue')
		},
		// 我的信息
		{
			path: '/archive',
			name: 'archive',
			component: () => import( /* webpackChunkName: 'view-archive' */
				'../views/archive/index.vue')
		}
	]

},
{
	path: '/screen',
	name: 'view-Sreen',
	component: Sreen,
	children: [
		{
			path: '/screen',
			name: 'view-sreen',
			component: () => import( /* webpackChunkName: 'view-dashboard' */
				'../views/dashboard/index.vue')
		},]
},
{
	path: '/login',
	name: 'view-login',
	component: Login
},
{
	path: '/logon',
	name: 'view-logon',
	component: Logon
},
{
	path: '*',
	name: 'view-404',
	component: () => import( /* webpackChunkName: 'view-404' */ '../views/404.vue')
}
]

const router = new VueRouter({
	routes
})

router.beforeEach((to, from, next) => {
	if (to.path === "/rfm-detail") {
		if (store.state.buttons.findIndex(item => item.path === "rfm-detail") >= 0) {
			next();
		} else {
			Message.error("您没有该页面访问权限");
		}
	} else if (to.path === "/rfm-setup") {
		if (store.state.buttons.findIndex(item => item.path === "rfm-setup") >= 0) {
			next();
		} else {
			Message.error("您没有该页面访问权限");
		}
	} else if (to.path === "/logon" && !store.state.token) {
		next();
	} else {
		if (to.path !== '/login' && !store.state.token) {
			next("/login");
		} else {
			next()
		}
	}
})

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}

export default router
